package com.af.example;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author : zhenyun.su
 * @comment : 提供简单加减除方法，用于测试，验证，实验新功能使用
 * @since : 2022/5/8
 */

public abstract class AfBaseExample {
    private Integer timeOut;
    private TimeUnit timeUnit;
    private Random random = new Random();
    private Boolean debug = false;


    public AfBaseExample(TimeUnit timeUnit, Integer timeOut) {
        this.timeOut = timeOut;
        this.timeUnit = timeUnit;
    }

    /*
     * @comment : 用于控制方法的执行耗时
     */
    protected void trySleep() {
        try {
            final int value = random.nextInt(timeOut);
            if (debug){
                System.out.println(random.nextInt(timeOut));
            }
            timeUnit.sleep(value);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void setDebug(Boolean debug) {
        this.debug = debug;
    }
}
